import request from '@/utils/request'

// 登录
export function login(data) {
  // 模拟登录验证
  const { username, password } = data
  return new Promise((resolve, reject) => {
    if (username === 'admin') {
      setTimeout(() => {
        resolve({
          data: {
            code: 200,
            data: {
              token: 'mock-token-' + Date.now(),
              username: username
            }
          }
        })
      }, 300)
    } else {
      reject(new Error('用户名或密码错误'))
    }
  })
}

// 登出
export function logout() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve({
        data: {
          code: 200,
          data: 'success'
        }
      })
    }, 300)
  })
}

// 获取当前用户信息
export function getInfo() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve({
        data: {
          code: 200,
          data: {
            roles: ['admin'],
            name: '管理员',
            avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif'
          }
        }
      })
    }, 300)
  })
}

// 修改密码
export function changePassword(data) {
  return request({
    url: '/api/auth/change-password',
    method: 'post',
    data
  })
}

// 重置密码
export function resetPassword(data) {
  return request({
    url: '/api/auth/reset-password',
    method: 'post',
    data
  })
}

// 获取验证码
export function getCaptcha() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve({
        data: {
          code: 200,
          data: {
            image_base64: ''
          }
        }
      })
    }, 300)
  })
} 